package com.atguigu.eduteacher.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduteacher.javabean.dto.VideoInfoDto;
import com.atguigu.eduteacher.service.IEduVideoService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-21
 */
@RestController
@RequestMapping("/eduservice/edu-video")
@RequiredArgsConstructor
@CrossOrigin
public class EduVideoController {

    private final IEduVideoService videoService;

    @ApiOperation(value = "新增课时")
    @PostMapping
    public R save(
            @ApiParam(name = "videoForm", value = "课时对象", required = true)
            @RequestBody VideoInfoDto videoInfoDto) {
        videoService.saveVideoInfo(videoInfoDto);
        return R.ok();
    }

    @ApiOperation(value = "根据ID查询课时")
    @GetMapping("{id}")
    public R getVideInfoById(
            @ApiParam(name = "id", value = "课时ID", required = true)
            @PathVariable String id) {
        VideoInfoDto videoInfoForm = videoService.getVideoInfoFormById(id);
        return R.ok().data("item", videoInfoForm);
    }

    @ApiOperation(value = "更新课时")
    @PutMapping("{id}")
    public R updateCourseInfoById(
            @ApiParam(name = "VideoInfoForm", value = "课时基本信息", required = true)
            @RequestBody VideoInfoDto videoInfoDto,
            @ApiParam(name = "id", value = "课时ID", required = true)
            @PathVariable String id) {
        videoService.updateVideoInfoById(videoInfoDto);
        return R.ok();
    }

    @ApiOperation(value = "根据ID删除课时")
    @DeleteMapping("{id}")
    public R removeById(
            @ApiParam(name = "id", value = "课时ID", required = true)
            @PathVariable String id) {
        boolean result = videoService.removeVideoById(id);
        if (result) {
            return R.ok();
        } else {
            return R.error().message("删除失败");
        }
    }

}
